package com.zhentao.datacontrol.domain.dto;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

public class DataControlRuleDTO {

    private Long id;

    private String ruleCode;

    @NotBlank(message = "规则名称不能为空")
    private String ruleName;

    @NotNull(message = "所属分组不能为空")
    private Long groupId;

    // 规则基本信息
    @NotNull(message = "有效开始时间不能为空")
    private LocalDate effectiveStartDate;

    private LocalDate effectiveEndDate;

    private Integer rulePriority;
    private String ruleDescription;

    @Email(message = "邮箱格式不正确")
    private String contactEmail;

    // 规则状态
    private String status;
    private String publishStatus;

    // 规则配置
    private Map<String, Object> ruleConfig;
    private String applicableYears;

    // 业务字段配置
    private List<BusinessFieldConfig> businessFields;
    private List<ParameterTableConfig> parameterTables;
    private Map<String, Object> filterConditions;

    private Integer sortOrder;

    // 非数据库字段
    private String groupName;
    private String statusText;
    private String publishStatusText;

    // 内部类：业务字段配置
    public static class BusinessFieldConfig {
        private String fieldName;
        private String fieldType;
        private String description;
        private boolean required;
        private String validationRule;

        // Getters and Setters
        public String getFieldName() { return fieldName; }
        public void setFieldName(String fieldName) { this.fieldName = fieldName; }

        public String getFieldType() { return fieldType; }
        public void setFieldType(String fieldType) { this.fieldType = fieldType; }

        public String getDescription() { return description; }
        public void setDescription(String description) { this.description = description; }

        public boolean isRequired() { return required; }
        public void setRequired(boolean required) { this.required = required; }

        public String getValidationRule() { return validationRule; }
        public void setValidationRule(String validationRule) { this.validationRule = validationRule; }
    }

    // 内部类：参数表配置
    public static class ParameterTableConfig {
        private String tableCode;
        private String tableName;
        private String keyField;
        private String valueField;
        private String validationType; // EXISTS, NOT_EXISTS, IN_RANGE

        // Getters and Setters
        public String getTableCode() { return tableCode; }
        public void setTableCode(String tableCode) { this.tableCode = tableCode; }

        public String getTableName() { return tableName; }
        public void setTableName(String tableName) { this.tableName = tableName; }

        public String getKeyField() { return keyField; }
        public void setKeyField(String keyField) { this.keyField = keyField; }

        public String getValueField() { return valueField; }
        public void setValueField(String valueField) { this.valueField = valueField; }

        public String getValidationType() { return validationType; }
        public void setValidationType(String validationType) { this.validationType = validationType; }
    }

    // Getters and Setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getRuleCode() { return ruleCode; }
    public void setRuleCode(String ruleCode) { this.ruleCode = ruleCode; }

    public String getRuleName() { return ruleName; }
    public void setRuleName(String ruleName) { this.ruleName = ruleName; }

    public Long getGroupId() { return groupId; }
    public void setGroupId(Long groupId) { this.groupId = groupId; }

    public LocalDate getEffectiveStartDate() { return effectiveStartDate; }
    public void setEffectiveStartDate(LocalDate effectiveStartDate) { this.effectiveStartDate = effectiveStartDate; }

    public LocalDate getEffectiveEndDate() { return effectiveEndDate; }
    public void setEffectiveEndDate(LocalDate effectiveEndDate) { this.effectiveEndDate = effectiveEndDate; }

    public Integer getRulePriority() { return rulePriority; }
    public void setRulePriority(Integer rulePriority) { this.rulePriority = rulePriority; }

    public String getRuleDescription() { return ruleDescription; }
    public void setRuleDescription(String ruleDescription) { this.ruleDescription = ruleDescription; }

    public String getContactEmail() { return contactEmail; }
    public void setContactEmail(String contactEmail) { this.contactEmail = contactEmail; }

    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }

    public String getPublishStatus() { return publishStatus; }
    public void setPublishStatus(String publishStatus) { this.publishStatus = publishStatus; }

    public Map<String, Object> getRuleConfig() { return ruleConfig; }
    public void setRuleConfig(Map<String, Object> ruleConfig) { this.ruleConfig = ruleConfig; }

    public String getApplicableYears() { return applicableYears; }
    public void setApplicableYears(String applicableYears) { this.applicableYears = applicableYears; }

    public List<BusinessFieldConfig> getBusinessFields() { return businessFields; }
    public void setBusinessFields(List<BusinessFieldConfig> businessFields) { this.businessFields = businessFields; }

    public List<ParameterTableConfig> getParameterTables() { return parameterTables; }
    public void setParameterTables(List<ParameterTableConfig> parameterTables) { this.parameterTables = parameterTables; }

    public Map<String, Object> getFilterConditions() { return filterConditions; }
    public void setFilterConditions(Map<String, Object> filterConditions) { this.filterConditions = filterConditions; }

    public Integer getSortOrder() { return sortOrder; }
    public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }

    public String getGroupName() { return groupName; }
    public void setGroupName(String groupName) { this.groupName = groupName; }

    public String getStatusText() { return statusText; }
    public void setStatusText(String statusText) { this.statusText = statusText; }

    public String getPublishStatusText() { return publishStatusText; }
    public void setPublishStatusText(String publishStatusText) { this.publishStatusText = publishStatusText; }
}
